local skynet = require "skynet"
local filelog = require "filelog"
local msghelper = require "agenthelper"
local msgproxy = require "msgproxy"
local table = table
local processstate = require "processstate"
local globaldatadao = require "globaldatadao"
local timetool = require "timetool"
local configdao = require "configdao"
require "enum"
local processing = processstate:new({timeout=4})

local  GetMarquees = {}

--[[
//获取跑马灯
message GetMarqueesReq {
    optional Version version = 1;
}

message GetMarqueesRes {
    optional int32 errcode = 1;
    optional string errcodedes = 2;
    repeated SystemMessageItem marquees = 3;
}
]]

function  GetMarquees.process(session, source, fd, request)
    local responsemsg = {
        errcode = EErrCode.ERR_SUCCESS,
    }
    local server = msghelper:get_server()

    --检查当前登陆状态
    if not msghelper:is_login_success() then
        filelog.sys_warning("GetMarquees.process invalid server state", server.state)
        responsemsg.errcode = EErrCode.ERR_INVALID_REQUEST
        responsemsg.errcodedes = "无效的请求！"
        msghelper:send_resmsgto_client(fd, "GetMarqueesRes", responsemsg)
        return
    end

    if processing:is_processing() then
        responsemsg.errcode = EErrCode.ERR_DEADING_LASTREQ
        responsemsg.errcodedes = "正在处理上一次请求！"
        msghelper:send_resmsgto_client(fd, "GetMarqueesRes", responsemsg)
        return
    end

    local status
    local marquees

    processing:set_process_state(true)

    status, marquees = globaldatadao.query_marquees()

    processing:set_process_state(false)

    if not msghelper:is_login_success() then
        filelog.sys_warning("GetMarquees.process invalid server state", server.state)
        responsemsg.errcode = EErrCode.ERR_INVALID_REQUEST
        responsemsg.errcodedes = "无效的请求！"
        msghelper:send_resmsgto_client(fd, "GetMarqueesRes", responsemsg)
        return
    end

    if marquees == nil then
        responsemsg.errcode = EErrCode.ERR_INVALID_REQUEST
        responsemsg.errcodedes = "访问数据失败！"
        msghelper:send_resmsgto_client(fd, "GetMarqueesRes", responsemsg)
        return        
    end

    responsemsg.marquees = marquees
    	
    msghelper:send_resmsgto_client(fd, "GetMarqueesRes", responsemsg)

end

return GetMarquees
